<!DOCTYPE html>
<html class="x-admin-sm">

    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="../../css/font.css">
        <link rel="stylesheet" href="../../css/xadmin.css">
        <script src="../../js/base.js" type="text/javascript" charset="utf-8"></script>
        <script src="../../lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../../js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>

    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">基础设置</a>
                <a>
                    <cite>绩效人员设置</cite></a>
            </span>
            <a class="layui-btn layui-btn-small select" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()"
             title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <script type="text/html" id="barDemo">
          <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon"></i>删除</a>
        </script>
		<script type="text/html" id="switchTpl">
		  <!-- 这里的 checked 的状态只是演示 -->
		  <input type="checkbox" name="isbonus" value="{{d.st_date}}-{{d.dept_code}}-{{d.user_id}}" lay-skin="switch" lay-text="是|否" lay-filter="set_isbonus" {{ d.isbonus == 1 ? 'checked' : '' }}>
		</script>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        
                        <div class="layui-card-body ">
							<div class="layui-inline" style="margin-left:10px">
								<label >核算月份</label>
								<div class="layui-input-inline">
									<input type="text" id="st_date_text" name="name_text" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline" style="margin-left:10px">
								<label >科室名称</label>
								<div class="layui-input-inline">
									<form class="layui-form">
									  <select lay-filter="sys_dept_dict" id="sys_dept_dict" name="sys_dept_dict">
										<option value="">全部</option>
									  </select>
									</form>
								</div>
							</div>
							<div class="layui-inline" style="margin-left:10px">
								<label >姓名</label>
								<div class="layui-input-inline">
									<input type="text" id="name_text" name="name_text" autocomplete="off" class="layui-input">
								</div>
							</div>
							
							
							<div class="layui-inline" style="margin-left:10px">
								<button class = "layui-btn select layui-btn-sm" onclick="select()"  id="btn_select" style="display:none" > <i class="layui-icon"></i>查询 </button>
							</div>
							<div class="layui-inline" style="margin-left:10px">
								<button class = "layui-btn select layui-btn-sm" onclick="add()"  id="btn_add" style="display:none" ><i class="layui-icon"></i>添加 </button>
							</div>
							<div class="layui-inline" style="margin-left:10px">
								<button class = "layui-btn select layui-btn-sm" onclick="show()" ><i class="layui-icon">&#xe60c;</i> 人员信息 </button>
							</div>
                            <table class="layui-table" lay-filter="table" id="table">
                                
                            </table>
                        </div>
						
						<!-- <div class="layui-card-body ">
							
							<div class="layui-inline" style="margin-left:10px">
								<label >科室名称</label>
								<div class="layui-input-inline">
									<form class="layui-form">
									  <select lay-filter="sys_dept_dict" id="sys_dept_dict" name="sys_dept_dict">
										<option value="">全部</option>
									  </select>
									</form>
								</div>
							</div>
							
							<div class="layui-inline" style="margin-left:10px">
								<button class = "layui-btn select layui-btn-sm" onclick="select()"  id="btn_select" style="display:none" > <i class="layui-icon"></i>查询 </button>
							</div>
							
						    <table class="layui-table" lay-filter="table" id="table1">
						        
						    </table>
						</div> -->
						
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script type="text/html" id="toolbarDemo">
        <div class = "layui-btn-container" > 
            <button class = "layui-btn select layui-btn-sm" lay-event = "add" id="btn_add" style="display:none" ><i class="layui-icon"></i>添加 </button>
        </div > 
    </script>
    
    <script>
		
        layui.use("laydate",
            function() {
                var laydate = layui.laydate;

                //执行一个laydate实例
                laydate.render({
                    elem: "#st_date_text", //指定元素
					type:"month"
                });

                //执行一个laydate实例
                laydate.render({
                    elem: "#end" //指定元素
                });

            });
    </script>
    <script>
		var table = null;
		var form = null;
        layui.use(["table","form"],
            function() {
                table = layui.table;
				form = layui.form;
                
				 
				// table.render({
				//     elem: "#table1"
				//     ,url: root+"Jixiaorenyuanshezhi/get_list" 
				//     ,page: true
				//     ,cols: [[ //表头
				//         {align:"center",field: "dept_name", title: "科室名称"}
				// 		,{align:"center",field: "user_id", title: "工号"}
				//         ,{align:"center",field: "staff_name", title: "核算人员"}
				//         ,{align:"center",field: "isbonus", title: "是否发放奖金",templet: '#switchTpl'}
				//         ,{align:"center",field: "days", title: "工作日"}
				//         ,{align:"center",field: "personsmodulus", title: "人员系数"}
				// 		,{align:"center",fixed: "right", title:"操作", toolbar: "#barDemo", cellMinWidth:80}
				//     ]],id:"table"
				//  });
                
                //监听单元格编辑
                table.on("tool(table)", function(obj){
                    
                    var data = obj.data;
                    //console.log(obj)
                    if(obj.event === "del"){
                      layer.confirm("真的删除行么", function(index){
                        // console.log(data.uuid);
                        
                        var uuid = data.uuid
                        $.post(root + "index/table_delete", {
                                uuid: uuid,
                                table:"set_checkbonusdays"
                            },
                            function(data) {
                                if(data.code == 0)
                                {
                                    obj.del();
                                    layer.alert(data.msg, {
                                        icon: 6
                                    });
                                }
                                else
                                {
                                    layer.alert(data.msg, {
                                        icon: 2
                                    });
                                }
                            }
                        );
                        
                        layer.close(index);
                      });
                    } 
                    
                    if(obj.event === "edit"){
                        
                        var data = obj.data;
                        console.log(data);
                        xadmin.open("编辑","edit.html?uuid="+data.uuid,800,600)
                        
                    }
                    
                });
                table.on("tool(test)",
                    function(obj) {
                        
                    });
				
				table.on('edit(table)', function(obj){
				    var value = obj.value //得到修改后的值
				    ,data = obj.data //得到所在行所有键值
				    ,field = obj.field; //得到字段
				    field = field.toUpperCase();
					
					$.post(root+"Jixiaorenyuanshezhi/set_field", 
					{
						uuid:data.uuid,
						days:data.days,
						personsmodulus:data.personsmodulus
					},
					function(data) {
					        
							if(data.code == 0)
							{
							    layer.msg(data.msg, {
							        icon: 6
							    });
							}
							else
							{
							    layer.msg(data.msg, {
							        icon: 2
							    });
							}
					    }
					);
					
				  });
				
                //头工具栏事件
                table.on("toolbar(table)",
                    function(obj) {
                        var checkStatus = table.checkStatus(obj.config.id);
                        switch (obj.event) {
                            case "add":
                                xadmin.open("添加","add.html",800,600)
                                break;
                            case "getCheckLength":
                                var data = checkStatus.data;
                                layer.msg("选中了：" + data.length + " 个");
                                break;
                            case "isAll":
                                layer.msg(checkStatus.isAll ? "全选" : "未全选");
                                break;
                        };
                    });
					
					
				$.post(root+"Jixiaorenyuanshezhi/get_sys_dept_dict", {},
				    function(data) {
				        
						for(var i = 0 ; i < data.data.length ; i++)
						{
							$('#sys_dept_dict').append("<option value='"+data.data[i].dept_code+"'>"+data.data[i].dept_name+"</option>");
						}
						
						form.render('select');
				    }
				);
				
				
				form.on('switch(set_isbonus)', function(obj){
					var arr = this.value.split("-");
					var isbonus = obj.elem.checked;
					if(isbonus)
					{
						isbonus = 1;
					}
					else
					{
						isbonus = 0;
					}
				    $.post(root+"Jixiaorenyuanshezhi/save_one", 
					{
						st_date:arr[0],
						dept_code:arr[1],
						user_id:arr[2],
						isbonus:isbonus
					},
				    function(data) {
				            
				    		if(data.code == 0)
				    		{
				    		    layer.tips(data.msg,obj.othis);
				    		}
				    		else
				    		{
				    		    layer.alert(data.msg,obj.othis);
				    		}
				        }
				    );
				});
				set_role_list("绩效人员设置");
            });
			
			function select()
			{
				table.render({
				    elem: "#table"
				    ,url: root+"Jixiaorenyuanshezhi/get_list" 
				    ,page: true
				    ,cols: [[ //表头
				        {align:"center",field: "dept_name", title: "科室名称"}
						,{align:"center",field: "user_id", title: "工号"}
				        ,{align:"center",field: "staff_name", title: "核算人员"}
				        ,{align:"center",field: "isbonus", title: "是否发放奖金",templet: '#switchTpl'}
				        ,{align:"center",field: "days", title: "工作日",edit:"text"}
				        ,{align:"center",field: "personsmodulus", title: "人员系数",edit:"text"}
						,{align:"center",fixed: "right", title:"操作", toolbar: "#barDemo", cellMinWidth:80}
				    ]],id:"table"
				 });
				 
				table.reload('table',
				{
				  where:{
					name:$('#name_text').val(),
					dept_code:$('#sys_dept_dict').val(),
					st_date:$('#st_date_text').val()
				  }
				});
			}
			
			function add()
			{
				xadmin.open("添加","add.html",800,600)
			}
			
			function show()
			{
				var st_date = $('#st_date_text').val();
				if(st_date == null || st_date == undefined || st_date == "")
				{
					return false;
				}
				xadmin.open("人员信息","staff_list.html?st_date="+st_date,800,600)
			}
			
    </script>
    <script>
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

</html>
